package com.sky.controller.admin;


import com.sky.result.Result;
import io.swagger.v3.oas.annotations.tags.Tags;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

/**
 * 管理端:店铺营业状态
 */
@RestController("adminShopController")
@RequestMapping("/admin/shop")
@Slf4j
public class ShopController {
    public static final String SHOP_STATUS = "shop_status";

    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 查询店铺营业状态
     *
     * @return
     */
    @GetMapping("/status")
    public Result<Integer> getStatus() {
        log.info("查询店铺营业状态");
        Integer shop_status = (Integer) redisTemplate.opsForValue().get(SHOP_STATUS);
        return Result.success(shop_status);
    }

    /**
     * 修改店铺营业状态
     *
     * @param status
     * @return
     */
    @PutMapping("/{status}")
    public Result startOrStop(@PathVariable Integer status) {
        log.info("店铺状态:{}", status == 1 ? "营业中" : "打样中");
        redisTemplate.opsForValue().set(SHOP_STATUS, status);
        return Result.success();
    }
}
